package controllers

import (
	"github.com/astaxie/beego"
	"github.com/astaxie/beego/cache"
	"github.com/astaxie/beego/utils/captcha"
	//"github.com/astaxie/beego/orm"
	//"encoding/json"
	"057dg/models"
)

var cpt *captcha.Captcha

func init() {
	// use beego cache system store the captcha data
	store := cache.NewMemoryCache()
	cpt = captcha.NewWithFilter("/captcha/", store)
	cpt.StdWidth = 80
	cpt.StdHeight = 40
	cpt.ChallengeNums = 4
}

type HomeController struct {
	beego.Controller
}

func (this *HomeController) Get() {
	this.Layout = "layout/layout.html"
	this.Data["Website"] = "beego.me"
	this.Data["Email"] = "astaxie@gmail.com"
	this.Data["IsLogin"] = checkAccount(this.Ctx)
	this.TplNames = "home/index.html"
}

func (this *HomeController) Login() {
	this.TplNames = "home/login.html"
}

func (this *HomeController) Regedit() {
	this.TplNames = "home/regedit.html"
}

func (this *HomeController) CheckEmail() {

	//abc := this.Ctx.Input.RequestBody()
	//var maps map[string]interface{}
	//json := json.Unmarshal(this.Ctx.Input.RequestBody, &maps)
	types := this.GetString("type")
	email := this.GetString("email")

	if types == "2" {
		_, err := models.GetUserByEmail(email)
		if err != nil {
			this.Data["json"] = err
		} else {
			this.Data["json"] = "没查到"
		}
	} else {
		this.Data["json"] = 200
	}

	this.ServeJson()
}
